<template>
	<view>
		<mumu-get-qrcode @success='qrcodeSucess' :definition="true" @error="qrcodeError"></mumu-get-qrcode>
		<fukuanmsg :show="messagefk.fkshow" :paystatus="messagefk.paystatus"></fukuanmsg>
	</view>
</template>

<script>
	import mumuGetQrcode from '@/uni_modules/mumu-getQrcode/components/mumu-getQrcode/mumu-getQrcode.vue'
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		components: {
			mumuGetQrcode
		},
		data() {
			return {
				listid:"",
				messagefk:{
					fkshow:false,
					paystatus:1,//1成功，2失败
				},
				type:1,//1加总结账进入需要直接返回不需要其他操作的页面，2pos点餐进入，3呼叫訂單，4預約訂單
			};
		},
		onLoad(options) {
			this.listid = options.id
			this.type = options.type
			// this.qrcodeSucess("20250417204048ZF5Y912")
		},
		methods: {
			qrcodeSucess(data) {
				if(this.type!=1 || this.type!=2) return false //其他的收款還沒做好先不走
				uni.showLoading({
					mask:true,
					title:"請稍後"
				})
				httpRequest.request("/api/pay/userMoenyScan", "POST", {
					shop_id: uni.getStorageSync("shop_id"),
					id:this.listid,
					paycode:data,
				}).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						this.messagefk = {
							fkshow:true,
							paystatus:1
						}
						setTimeout(()=>{
							this.messagefk = {
								fkshow:false,
								paystatus:1
							}
							if(this.type==1){
								uni.navigateBack(1)
							}else{
								uni.reLaunch({
									url: "/pages/index/index"
								})
							}
						},1000)
					} else {
						this.messagefk = {
							fkshow:true,
							paystatus:2
						}
						setTimeout(()=>{
							this.messagefk = {
								fkshow:false,
								paystatus:2
							}
							if(this.type==1){
								uni.navigateBack(1)
							}else{
								uni.reLaunch({
									url: "/pages/index/index"
								})
							}
						},1000)
					} 
				})
			},
			qrcodeError(err) {
				console.log(err)
				uni.showModal({
					title: '監視器授權失敗',
					content: '監視器授權失敗，請檢測當前瀏覽器是否有監視器許可權。',
					success: () => {
						uni.navigateBack({})
					}
				})
			},
		},
	};
</script>

<style></style>